package com.coder4j.platform.mapper;

import com.coder4j.starter.mybatis.BaseMapper;
import com.coder4j.platform.entity.SysContentEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Arrays;
import java.util.List;

/**
 * 内容表，笔记、文章、教程等
 * @author keller
 * @date 2025-05-31 19:08:27
 */
@Mapper
public interface SysContentMapper extends BaseMapper<SysContentEntity>{
	/**
     * 默认查询条件
     * @return
     */
    @Override
    default List<String> defaultCondition(){
    return Arrays.asList(
			" <if test = 'groupId!=null'> AND group_id=#{groupId} </if>",
            " <if test = 'createId!=null'> AND create_id=#{createId} </if>",
            " <if test = 'updateId!=null'> AND update_id=#{updateId} </if>");
    }

    /**
     * <!-- sys_content_mapper.xml -->
     * <select id="getListByGroupIds" resultType="SysContentEntity">
     *     SELECT id, group_id, title
     *     FROM sys_content
     *     WHERE group_id IN
     *     <foreach item="id" collection="ids" open="(" separator="," close=")">
     *         #{id}
     *     </foreach>
     * </select>
     * @param idList
     * @return
     */

    @Select({
            "<script>",
            " SELECT id,group_id,title from sys_content ",
            " WHERE group_id IN ",
            " <foreach collection='idList' item='id' index='index' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    List<SysContentEntity> getListByGroupIds(@Param("idList") List<Long> idList);
}